package com.huike.controller.system;

import com.huike.dto.PageUserDto;
import com.huike.dto.SysUserDto;
import com.huike.entity.SysUser;
import com.huike.result.PageResult;
import com.huike.result.Result;
import com.huike.service.UserService;
import com.huike.vo.SysUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 用户分页查询
     *
     * @param dto
     * @return
     */
    @GetMapping("list")
    public Result<PageResult<SysUserVo>> list(PageUserDto dto) {
        return userService.list(dto);
    }

    /**
     * 添加用户
     *
     * @param dto
     * @return
     */
    @PostMapping("add")
    public Result add(@RequestBody SysUserDto dto) {
        return userService.add(dto);
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @DeleteMapping("delete/{id}")
    public Result delete(@PathVariable Integer id) {
        return userService.delete(id);
    }

    /**
     * 根据id查询回显
     * @param id
     * @return
     */
    @GetMapping("findById/{id}")
    public Result<SysUser> findById(@PathVariable Integer id){
       return userService.findById(id);
    }

    /**
     * 修改用户
     * @param dto
     * @return
     */
    @PutMapping("update")
    public Result update(@RequestBody SysUserDto dto){
        return userService.update(dto);
    }


}
